package com.shy;

import java.util.Hashtable;


/**
 * Created by huangyang on 2017/2/1.
 */
public class ShapeCache {
    private static Hashtable<String, Shape> shapMap = new Hashtable<String, Shape>();

    public static Shape getShape(String shapeId) throws CloneNotSupportedException {
        Shape cachedShape = shapMap.get(shapeId);
        return (Shape) cachedShape.clone();
    }

    public static void loadShape() {
        Circle circle = new Circle();
        circle.setId("1");
        shapMap.put(circle.getId(), circle);

        Square square = new Square();
        square.setId("2");
        shapMap.put(square.getId(), square);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("3");
        shapMap.put(rectangle.getId(), rectangle);
    }
}
